package com.gec.it.web;


import com.gec.it.entity.Jobs;
import com.gec.it.service.JobsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 欧阳
 * @since 2022-01-04
 */
@Controller
@RequestMapping("/jobs")
public class JobsController {

    @Autowired
    private JobsService service;

    @GetMapping("/add")
    public String add(){
        return "job_add";
    }

    @PostMapping("/add")
    public String add(Jobs job){
        service.save(job);
        return "redirect:list";
    }

    @GetMapping("/list")
    public String jobList(Model m){
        final List<Jobs> list = service.list();
        m.addAttribute("list",list);
        return "job_list";
    }

    @GetMapping("/edit")
    public String edit(int id,Model m){
        final Jobs job = service.getById(id);
        m.addAttribute("j",job);
        return "job_edit";
    }

    @PostMapping("/edit")
    public String edit(Jobs job){
        service.updateById(job);
        return "redirect:list";
    }

    @GetMapping("/del")
    public String del(int id){
        service.removeById(id);
        return "redirect:list";
    }
}
